package knowse.app;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class ProjectEntryDataObject {

	SimpleDateFormat df;
	Calendar calendar;
	private Date timeStamp;
	private Date startDate;
	private Date startTime;
	private float elapsedTime;
	private int numTests;
	private int numAssertions;
	private int numFailures;
	private int numErrors;
	private int numSkips;
	
	
	public ProjectEntryDataObject(String csvLine){
		String[] lineValues = csvLine.split(",");
		String date = lineValues[0];
		String time = lineValues[1];
		String elapsedTime = lineValues[2];
		String numTests = lineValues[3];
		String numAssertions = lineValues[4];
		String numFailures = lineValues[5];
		String numErrors = lineValues[6];
		String numSkips = lineValues[7];
		calendar = new GregorianCalendar();
		
		try {
			df = new SimpleDateFormat("yyyy-MM-dd HH:mm.ss");
			this.timeStamp = df.parse(date + " " + time);
			calendar.setTime(timeStamp);
			this.elapsedTime = Float.parseFloat(elapsedTime);
			this.numTests=Integer.parseInt(numTests);
			this.numAssertions= Integer.parseInt(numAssertions);  
			this.numFailures=Integer.parseInt(numFailures);
			this.numErrors=Integer.parseInt(numErrors);
			this.numSkips=Integer.parseInt(numSkips);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
		
	public String toString(){
		String result = 
				df.format(timeStamp);
		result += " " + elapsedTime + 
				  " " + numTests +
				  " " + numAssertions +
				  " " + numErrors +
				  " " + numSkips;
		
		return result;
	}
	
	
	public Date getStartDate() {
		return getFragmentDate("yyyy-MM-dd");
	}
//	//test
//	public String getStartDateString(){
//		SimpleDateFormat bla = new SimpleDateFormat("yyyy-MM-dd");
//		return bla.format(getStartDate());
//		
//	}
//	//test
//	public String getStartTimeString(){
//		SimpleDateFormat bla = new SimpleDateFormat("HH:mm.ss");
//		return bla.format(getStartTime());
//		
//	}
	
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getStartTime() {
		return getFragmentDate("HH:mm:ss");
	}
	
	private Date getFragmentDate(String format){
		SimpleDateFormat dateFormat = new SimpleDateFormat(format);
		String dateString = dateFormat.format(timeStamp);
		Date dateDate = null;
		try{
			dateDate = dateFormat.parse(dateString);
		}catch(ParseException e){
			e.printStackTrace();
		}
		return dateDate;
	}
	
	

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public float getElapsedTime() {
		return elapsedTime;
	}

	public void setElapsedTime(int elapsedTime) {
		this.elapsedTime = elapsedTime;
	}

	public int getNumTests() {
		return numTests;
	}

	public void setNumTests(int numTests) {
		this.numTests = numTests;
	}

	public int getNumAssertions() {
		return numAssertions;
	}

	public void setNumAssertions(int numAssertions) {
		this.numAssertions = numAssertions;
	}

	public int getNumFailures() {
		return numFailures;
	}

	public void setNumFailures(int numFailures) {
		this.numFailures = numFailures;
	}

	public int getNumErrors() {
		return numErrors;
	}

	public void setNumErrors(int numErrors) {
		this.numErrors = numErrors;
	}

	public int getNumSkips() {
		return numSkips;
	}

	public void setNumSkips(int numSkips) {
		this.numSkips = numSkips;
	}
	

	
	
	
	
}
